package main

import (
	"fmt"
	"github.com/fatih/color"
	"github.com/hashicorp/hcl/v2"
	"github.com/ihaiker/tfwrapper/internal/cli"
	"github.com/ihaiker/tfwrapper/internal/util"
	"math/rand"
	"os"
	"runtime"
	"time"
)

var VERSION = "0.1.0"
var BUILD_TIME = "2020-01-01 04:04:04"
var BUILD_GIT_HASH = "HAIKER.DEV"

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	rand.Seed(time.Now().Unix())
	if err := cli.Execute(VERSION, BUILD_GIT_HASH, BUILD_TIME); err != nil {
		if diags, match := err.(hcl.Diagnostics); match {
			util.WriteDiagnostics(diags)
			if !util.HasErrors(diags) {
				return
			}
		} else {
			fmt.Println()
			color.HiRed("[ERROR] %s", err)
		}
		os.Exit(1)
	}
}
